﻿hpxAdminApp.controller('visitorRecordController', function ($rootScope, $scope, $stateParams, $state, API_URL, NgTableParams, commissionService) {
    $scope.filter = {
        deadlineTime1: '',
        deadlineTime2: '',
    };
    var emptyEntity = {};
    var newEntity = angular.copy(emptyEntity, newEntity);
    //初始化列表

    //console.log($stateParams)

    $scope.tableParams = new NgTableParams({ sorting: { 'enterprise_id': 'asc' } }, {
        getData: function (params) {
            return commissionService.getVisitorList(params,$stateParams.id, $scope.filter).then(function (data) {
                $scope.first = $scope.getFirst(params);
                if (data) {
                    return data.items;
                }
            });
        }
    });

    $scope.refresh = function () {
        $scope.tableParams.reload();
    };

    $scope.edit = function (data) {
        if (data == null) {
            $scope.model = newEntity;
        }
        else {
            $scope.model = angular.copy(data);
        }
        $('#modal-edit').modal('show');
    };

    $scope.save = function () {
        commissionService.update($scope.model).then(function () {
            $scope.tableParams.reload();
            $scope.editForm.$setPristine();
            $('#modal-edit').modal('hide');
        });
    };

    $("#start_time").datetimepicker({
        format: "yyyy-mm-dd",
        autoclose: true,
        minView: "month",
        maxView: "decade",
        todayBtn: true,
        pickerPosition: "bottom-left",
        language: 'zh-CN'
    }).on("click", function (ev) {
        $("#start_time").datetimepicker("setEndDate", $("#end_time").val());
    }).on('changeDate', function (e) {
        $scope.filter.deadlineTime1 = $("#start_time").val();
    });

    $("#end_time").datetimepicker({
        format: "yyyy-mm-dd",
        autoclose: true,
        minView: "month",
        maxView: "decade",
        todayBtn: true,
        pickerPosition: "bottom-left",
        language: 'zh-CN'
    }).on("click", function (ev) {
        $("#end_time").datetimepicker("setStartDate", $("#start_time").val());
    }).on('changeDate', function (e) {
        $scope.filter.deadlineTime2 = $("#end_time").val();
    });
});
